package cn.touna.jss.common.enums;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

public enum TongDunResultEnum {

    /************百融返回码*************/
    failUserAuth("001", "用户认证失败"),
    paramIsEmpty("101", "参数不能为空"),
    paramTypeError("102", "参数类型不正确"),
    paramExceedsLength("103", "参数超过最大长度"),
    NoAppId("130", "没有传递申请编号"),
    appIdNoCollaborate("131", "申请编号非本合作方所有"),
    appIdCradInconformity("132", "申请编号与身份证不符"),
    notFoundAppid("133", "找不到对应申请编号或申请编号已过期"),
    noBuyService("301", "没有购买服务"),
    disabled("302", "已被禁用"),
    underfed("303", "流量不足"),
    ExpirationOfServiceTime("304", "服务时间过期"),
    callTimeCapped("305", "日调用次数已达上限"),
    noPolicy("404", "没有对应的策略配置"),
    policyTimeouts("405", "策略执行超时"),
    InterExecError("500", "内部执行错误"),
    InterExecTimeout("505", "内部执行超时"),
    queryDataFail("701", "数据查询失败");

    /**
     * 枚举值
     */
    private final String value;

    /**
     * 枚举文本
     */
    private final String text;

    TongDunResultEnum(String value, String text) {
        this.value = value;
        this.text = text;
    }

    /**
     * {@inheritDoc}
     */
    public String value() {
        return value;
    }

    /**
     * 获取枚举对象文本
     *
     * @return String
     */
    public String text() {
        return text;
    }

    /**
     * 根据值获取枚举对象
     *
     * @param value 枚举值
     * @return 对象枚举对象
     */
    public static TongDunResultEnum getloanStatus(String value) {
        for (TongDunResultEnum status : values()) {
            if (status.value().equals(value)) {
                return status;
            }
        }
        return null;
    }


    /**
     * 根据code获取值
     *
     * @param code 枚举值
     * @return 对象枚举对象
     */
    public static String getValue(String code) {
        for (TongDunResultEnum status : values()) {
            if (status.value().equals(code)) {
                return status.text();
            }
        }
        return "";
    }


    /**
     * ENUM 转换成MAP
     */
    private static final Map<String, String> riskStatusMap = new HashMap<String, String>();

    static {
        for (TongDunResultEnum it : EnumSet.allOf(TongDunResultEnum.class)) {
            riskStatusMap.put(it.value(), it.text());
        }
    }


    public static void main(String[] args) {
//    	  BaiRongResultEnum getloanStatus = BaiRongResultEnum.getloanStatus("1");
//    	  System.out.println(getloanStatus.value());
//    	  System.out.println(getloanStatus.text());
//        getloanStatus("0");
//        Iterator<String> iterator = riskStatusMap.keySet().iterator();
//        while (iterator.hasNext()){
//            String key = iterator.next();
//            System.out.print("key:"+ key);
//            System.out.println(" value:"+riskStatusMap.get(key));
//        }
//         String value = getValue("1");
//         System.out.println(" value:"+ TongDunResultEnum.success.text());


    }


}
